package com.my.algorithmlearning.leetcode;

/**
 * @ClassName Medium_287_findDuplicate
 * @Description Medium_287_findDuplicate
 * @Author wanghaiwei
 * @Date 2023/7/19 14:02
 */
public class Medium_287_findDuplicate {
    public int findDuplicate(int[] nums) {
        int[] numBucket = new int[100_000];
        for (int i = 0; i < nums.length; i++) {
            numBucket[nums[i]]++;
        }
        for (int i = 0; i < numBucket.length; i++) {
            if (numBucket[i] > 1) {
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        Medium_287_findDuplicate findDuplicate = new Medium_287_findDuplicate();
        System.out.println(findDuplicate.findDuplicate(new int[]{1, 3, 4, 2, 2}));
        System.out.println(findDuplicate.findDuplicate(new int[]{3, 1, 3, 4, 2}));
        System.out.println(findDuplicate.findDuplicate(new int[]{1, 1}));
        System.out.println(findDuplicate.findDuplicate(new int[]{3,2,5,14,5,5,19,18,11,10,1,4,5,5,5,5,12,5,17,5}));
    }
}
